using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.Practices.EnterpriseLibrary.Data.Sql;
using System.Data.SqlClient;
using System.Data.Common;

public partial class rptServicePack : System.Web.UI.Page
{
    Microsoft.Practices.EnterpriseLibrary.Data.Database db = DatabaseFactory.CreateDatabase("Application_Data");

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {    
            Update();
        }
    }

    protected void Update()
    {
        Microsoft.Practices.EnterpriseLibrary.Data.Database db = DatabaseFactory.CreateDatabase("Application_Data");

        string sqlQuery = "SELECT CASE LEFT(InstanceVersion,4) WHEN '7.00' THEN 'SQL Server 7.0' WHEN '8.00' THEN 'SQL Server 2000' WHEN '9.00' THEN 'SQL Server 2005' WHEN '10.0' THEN 'SQL Server 2008' WHEN '10.5' THEN 'SQL Server 2008 R2' WHEN '11.0' THEN 'SQL Server 2012' ELSE 'Unknown' END AS 'InstanceVersion', InstanceServicePack, InstanceVersion AS InstanceBuild, Count(*) AS Total FROM Instance i with (nolock) GROUP BY i.InstanceVersion,InstanceServicePack ORDER BY InstanceBuild DESC";
        string sqlQuery2 = "SELECT InstanceOSVersion, Count(*) AS Total FROM Instance i with (nolock) GROUP BY InstanceOSVersion ORDER BY InstanceOSVersion DESC";

        DataSet ds = db.ExecuteDataSet(CommandType.Text, sqlQuery);
        DataSet ds2 = db.ExecuteDataSet(CommandType.Text, sqlQuery2);

        gv.DataSource = ds;
        gv.DataBind();

        gv2.DataSource = ds2;
        gv2.DataBind();

    }
}
